package com.vca.service.service.Impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vca.common.model.product.StoreProductAttr;
import com.vca.common.model.product.StoreProductAttrValue;
import com.vca.common.model.vca_product.VcaProductAttr;
import com.vca.service.dao.vca_product.VcaProductAttrDao;
import com.vca.service.service.VcaProductAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商品属性表 服务实现类
 * </p>
 *
 * @author chenBing
 * @since 2022-11-16
 */
@Service
public class VcaProductAttrServiceImpl extends ServiceImpl<VcaProductAttrDao, VcaProductAttr> implements VcaProductAttrService {

    @Autowired
    private VcaProductAttrDao dao;

    /**
     * 根据商品属性查询
     *
     * @param vcaProductAttr 商品属性参数
     * @return 商品属性结果
     */
    @Override
    public List<VcaProductAttr> getByEntity(VcaProductAttr vcaProductAttr) {
        LambdaQueryWrapper<VcaProductAttr> lqw = new LambdaQueryWrapper<>();
        lqw.setEntity(vcaProductAttr);
        return dao.selectList(lqw);
    }

    /**
     * @param shopId  商品ID
     * @param shopType 商品类型
     * @Description:获取商品规格
     * @Author: chenBing
     * @Date: 2022/11/18
     */
    @Override
    public List<VcaProductAttr> getListByProductIdAndType(Integer shopId, Integer shopType) {
        LambdaQueryWrapper<VcaProductAttr> lqw = new LambdaQueryWrapper<>();
        lqw.eq(VcaProductAttr::getProductId,shopId);
        lqw.eq(VcaProductAttr::getType,shopType);
        lqw.eq(VcaProductAttr::getIsDeleted,false);
        return list(lqw);
    }

    /**
     * 删除商品规格
     * @param productId 商品id
     * @param type 商品类型
     * @return Boolean
     */
    @Override
    public Boolean deleteByProductIdAndType(Integer productId, Integer type) {
        LambdaUpdateWrapper<VcaProductAttr> luw = Wrappers.lambdaUpdate();
        luw.set(VcaProductAttr::getIsDeleted, true);
        luw.eq(VcaProductAttr::getProductId, productId);
        luw.eq(VcaProductAttr::getType, type);
        return update(luw);
    }
}
